﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ParangonBiz.Tools;

namespace ParangonBiz.Master
{
    public partial class ViewPageStandart : System.Web.UI.MasterPage
    {
        //protected SiteMapNode CurrentNode
        //{
        //    get { return (SiteMapNode)ViewState["CurrentNode"]; }
        //    set { ViewState["CurrentNode"] = value; }
        //}

        protected void Page_Load(object sender, EventArgs e)
        {
            Uri urlList;
            if (Uri.TryCreate(Request.Url, ConfigReader.UrlList, out urlList))
            {
                if (Request.Url.GetLeftPart(UriPartial.Path) == urlList.GetLeftPart(UriPartial.Path))
                {
                    //if (!String.IsNullOrEmpty(Request.QueryString["id"]))
                    //{
                    //    smpBreadCrumbs.Provider = null;
                        
                    //    smpBreadCrumbs.Provider = SiteMap.Providers["DefaultXmlSiteMapProvider"]; 

                    //    //smpBreadCrumbs.RenderCurrentNodeAsLink = true;
                    //    //SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.ExpandForumPaths);
                    //}
                    //else
                    //{
                    //    smpBreadCrumbs.Provider = null;
                    //    smpBreadCrumbs.Provider = SiteMap.Providers["SiteMapDataProvider"];
                    //}
                }
            }
        }

        //private SiteMapNode ExpandForumPaths(Object sender, SiteMapResolveEventArgs e)
        //{
        //    // The current node represents a Post page in a bulletin board forum. 
        //    // Clone the current node and all of its relevant parents. This 
        //    // returns a site map node that a developer can then 
        //    // walk, modifying each node.Url property in turn. 
        //    // Since the cloned nodes are separate from the underlying 
        //    // site navigation structure, the fixups that are made do not 
        //    // effect the overall site navigation structure.

            
        //    if (SiteMap.CurrentNode != null)
        //    {
        //        CurrentNode = SiteMap.CurrentNode;

        //        SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
        //        SiteMapNode tempNode = currentNode;

        //        // Obtain the recent IDs. 
        //        int forumGroupId = GetMostRecentForumGroupID();
        //        int forumId = GetMostRecentForumID(forumGroupId);
        //        int postId = GetMostRecentPostID(forumId);

        //        // The current node, and its parents, can be modified to include 
        //        // dynamic querystring information relevant to the currently 
        //        // executing request. 
        //        if (0 != postId)
        //        {
        //            tempNode.Url = string.Format("{0}?PostID={1}", tempNode.Url, postId);
        //        }

        //        if ((null != (tempNode = tempNode.ParentNode)) &&
        //            (0 != forumId))
        //        {
        //            tempNode.Url = string.Format("{0}?ForumID={1}", tempNode.Url, forumId);
        //        }

        //        if ((null != (tempNode = tempNode.ParentNode)) &&
        //            (0 != forumGroupId))
        //        {
        //            tempNode.Url = string.Format("{0}?ForumGroupID={1}", tempNode.Url, forumGroupId);
        //        }

        //        return currentNode;
        //    }
            
        //    if (CurrentNode != null)
        //    {
        //        SiteMapNode currentNode = CurrentNode.Clone(true);
        //        SiteMapNode tempNode = currentNode;

        //        currentNode.Url = string.Format("{0}?ForumGroupID={1}", tempNode.Url, 11313);

        //        SiteMapNode smn = new SiteMapNode(SiteMap.Provider, "dsfsd", e.Context.Request.RawUrl);
        //        smn.Title = "sdfsdfsdfsdfsdf";

        //        currentNode.ChildNodes = new SiteMapNodeCollection(smn);

        //        return currentNode.ChildNodes[0];
        //    }

        //    return null;
        //}

        //private int GetMostRecentForumGroupID()
        //{
        //    return 24;
        //}

        //private int GetMostRecentForumID(int forumGroupId)
        //{
        //    return 128;
        //}

        //private int GetMostRecentPostID(int forumId)
        //{
        //    return 317424;
        //}

    }
}